package com.badibadi.activity;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.util.LangUtils;

import com.badibadi.infos.CreateNewClubChoseTypeInfos;
import com.badibadi.infos.ListsModel;
import com.badibadi.infos.MasterModel;
import com.badibadi.infos.Results;
import com.badibadi.infos.UserInfoModel;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class DataSetChoseExpertApplyForTypeActivity extends
		ExpertApplyForChoseTypeActivity implements OnClickListener {

	public final int DADAACTIVITY = 0;
	private int Flags = DADAACTIVITY;

	private final int DATASET_RETURN_DATA = 0x56;
	private ListsModel listsModel;

	String LanguageType;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		LanguageType = com.badibadi.mytools.Dialog
				.getSystemLanguageType(DataSetChoseExpertApplyForTypeActivity.this);
		init();

	}

	private void init() {
		this.findViewById(R.id.expert_apply_for_chose_Return_btn)
				.setOnClickListener(this);

		TextView title = (TextView) this
				.findViewById(R.id.expert_appley_for_chose_type_title);
		title.setText(getResources().getString(R.string.SelectTalentType));
		TextView next_step = (TextView) this.findViewById(R.id.next_step);
		next_step.setText(getResources().getString(R.string.Finish));
		next_step.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				if (!GetDataId().equals("-1")) {
					Intent intent = new Intent(
							DataSetChoseExpertApplyForTypeActivity.this,
							ExpertApplyForActivity.class);
					UserInfoModel userInfoModel = (UserInfoModel) getIntent()
							.getSerializableExtra("userInfoModel");
					intent.putExtra("userInfoModel", userInfoModel);
					intent.putExtra("GetDataId", GetDataId());
					startActivity(intent);
					finish();
				} else {
					ShowToast(getApplicationContext(), getResources()
							.getString(R.string.l_xb68));
				}
				//    

				// String data=GetData();
				// if(data!="")
				// {
				// returnData(data);
				// // //返回数据
				// // Intent intent=new
				// Intent(DataSetChoseExpertApplyForTypeActivity.this,MyDataActivity.class);
				// // intent.putExtra("result", data);
				// // setResult(DATASET_RETURN_DATA,intent);
				// // finish();
				// }
				// else if(data=="")
				// {
				//
				// }
			}
		});
	}

	@Override
	protected void initItemNum(int num) {
		// TODO Auto-generated method stub
		super.initItemNum(num);
	}

	@Override
	public String[] getTuPianMing(String[] tupianming) {
		// TODO Auto-generated method stub
		return super.getTuPianMing(tupianming);
	}

	@Override
	public String[] getBeiJingTu(String[] beijingtu) {
		// TODO Auto-generated method stub
		return super.getBeiJingTu(beijingtu);
	}

	// /**复用选择达人需要重写两处，这是第一处*/
	// @Override
	// protected void initItemNum(int num) {
	// // TODO Auto-generated method stub
	// num=(new CreateNewClubChoseTypeInfos(
	// DataSetChoseExpertApplyForTypeActivity.this).getItem().length);
	//
	// super.initItemNum(num);
	// }
	// /**复用选择达人需要重写两处，这是第二处*/
	// @Override
	// public void initData(String[] tupianming, String[] beijingtu) {
	// // TODO Auto-generated method stub
	// CreateNewClubChoseTypeInfos experInfos = new CreateNewClubChoseTypeInfos(
	// this);
	// tupianming = experInfos.getItem();
	// beijingtu = experInfos.getPic();
	// }

	// private void returnData(String data){
	// //返回数据
	// Intent intent=new
	// Intent(DataSetChoseExpertApplyForTypeActivity.this,MyDataActivity.class);
	// intent.putExtra("result", data);
	// setResult(DATASET_RETURN_DATA,intent);
	// finish();
	// }
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		// returnData("");
		return super.onKeyDown(keyCode, event);
	}

	/**
	 * 重写四处 复用的话重写它（第一处） 要重写它
	 */
	@Override
	protected void initInterNet() {
		// TODO Auto-generated method stub
		Utils.showPrgress(DataSetChoseExpertApplyForTypeActivity.this);
		new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				listsModel = new ListsModel();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("type", "daren");
				map.put("languageType", LanguageType);
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "type/listType");
				//    
				if (content != null) {
					//    
					Results results = Utils.checkResult_NNN(
							DataSetChoseExpertApplyForTypeActivity.this,
							content);
					if (results != null && results.getRetmsg() != null) {
						//    
						try {
							listsModel = JSONUtils.getEntityByJsonString(
									results.getRetmsg(), ListsModel.class);
							if (listsModel.getLists() != null
									&& !listsModel.getLists().isEmpty()) {
								for (int i = 0; i < listsModel.getLists()
										.size(); i++) {
									MasterModel masterModel = new MasterModel();
									masterModel.setId(listsModel.getLists()
											.get(i).getId());
									masterModel.setName(listsModel.getLists()
											.get(i).getName());
									masterListView.add(masterModel);
								}
							}
							for (int i = 0; i < masterListView.size(); i++) {
								list.add(masterListView.get(i).getName());
							}
							ItemNum = masterListView.size();
							mHandler.sendEmptyMessage(0);

						} catch (Exception e) {
							// TODO Auto-generated catch block
							//    
							   
						}
					}
				} else {
					Utils.ExitPrgress(DataSetChoseExpertApplyForTypeActivity.this);
					mHandler.sendEmptyMessage(1);
				}
			}
		}).start();

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.expert_apply_for_chose_Return_btn) {
			// returnData("");
			this.finish();
		}

	}
}
